package com.ruoyi.paper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paper.domain.ExamFolder;
import com.ruoyi.paper.service.IExamFolderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷目录Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/jxsx/folder")
public class ExamFolderController extends BaseController
{
    private String prefix = "jxsx/folder";

    @Autowired
    private IExamFolderService examFolderService;

    @RequiresPermissions("jxsx:folder:view")
    @GetMapping()
    public String folder()
    {
        return prefix + "/folder";
    }

    /**
     * 查询试卷目录列表
     */
    @RequiresPermissions("jxsx:folder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamFolder examFolder)
    {
        startPage();
        List<ExamFolder> list = examFolderService.selectExamFolderList(examFolder);
        return getDataTable(list);
    }

    /**
     * 导出试卷目录列表
     */
    @RequiresPermissions("jxsx:folder:export")
    @Log(title = "试卷目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamFolder examFolder)
    {
        List<ExamFolder> list = examFolderService.selectExamFolderList(examFolder);
        ExcelUtil<ExamFolder> util = new ExcelUtil<ExamFolder>(ExamFolder.class);
        return util.exportExcel(list, "试卷目录数据");
    }

    /**
     * 新增试卷目录
     */
    @RequiresPermissions("jxsx:folder:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试卷目录
     */
    @RequiresPermissions("jxsx:folder:add")
    @Log(title = "试卷目录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamFolder examFolder)
    {
        return toAjax(examFolderService.insertExamFolder(examFolder));
    }

    /**
     * 修改试卷目录
     */
    @RequiresPermissions("jxsx:folder:edit")
    @GetMapping("/edit/{folderId}")
    public String edit(@PathVariable("folderId") String folderId, ModelMap mmap)
    {
        ExamFolder examFolder = examFolderService.selectExamFolderByFolderId(folderId);
        mmap.put("examFolder", examFolder);
        return prefix + "/edit";
    }

    /**
     * 修改保存试卷目录
     */
    @RequiresPermissions("jxsx:folder:edit")
    @Log(title = "试卷目录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamFolder examFolder)
    {
        return toAjax(examFolderService.updateExamFolder(examFolder));
    }

    /**
     * 删除试卷目录
     */
    @RequiresPermissions("jxsx:folder:remove")
    @Log(title = "试卷目录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examFolderService.deleteExamFolderByFolderIds(ids));
    }
}
